
bool isValid(char* s)
{
    char a[10000];
    int i = 0;
    int top = -1;
    int size = 0;
    while (s[i] != '\0')
    {
        if (s[i] == '(' || s[i] == '[' || s[i] == '{')
        {
            a[size] = s[i];
            size++;
            top++;
            i++;
        }
        if (s[i] == ')' || s[i] == ']' || s[i] == '}')
        {
            if (size == 0)
                return false;
            else
            {
                if (a[top] == '(' && s[i] == ')')
                {
                    i++;
                    size--;
                    top--;
                    continue;
                }
                if (a[top] == '[' && s[i] == ']')
                {
                    i++;
                    size--;
                    top--;
                    continue;
                }
                if (a[top] == '{' && s[i] == '}')
                {
                    i++;
                    size--;
                    top--;
                    continue;
                }
                return false;
            }
        }
    }
    if (size == 0)
        return true;
    else
        return false;
}
